package com.example.widgetevent;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.Toast;

public class FormActivity extends Activity {

	private RadioButton gmale;
	private RadioButton gfemale;
	private CheckBox jja;
	private CheckBox woo;
	private CheckBox tang;
	private String myjja = "";		//선택한 체크값을 저장
	private String mywoo = "";		
	private String mytang = "";
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_form);
		gmale = (RadioButton)findViewById(R.id.gmale);
		gfemale = (RadioButton)findViewById(R.id.gfemale);
		jja = (CheckBox)findViewById(R.id.jja);
		woo = (CheckBox)findViewById(R.id.woo);
		tang = (CheckBox)findViewById(R.id.tang);
		
	}

	//보통크기/작은크기 버튼클릭이벤트처리
	public void btnClick(View v) {
		String msg = "";
		
		switch (v.getId()) { //클릭이벤트를 발생시킨 주체를 DI로 넘겨받음 
		//case 문으로 그 주체를 확인한 다음 적절하게 이벤트 처리
		case R.id.nbtn: msg = "보통크기버튼이눌렀다!!!"; break;
		case R.id.sbtn: msg = "작은크기버튼눌렀다!!!"; break;
		}
		
		Toast.makeText(getApplicationContext(), msg , Toast.LENGTH_SHORT).show();
	}
	
	//성별 확인이벤트 처리
	public void checkGender( View v) {
		String result = "남자";
		//클릭한 라디오버튼의 체크여부 확인 (버튼클릭시 사용)
		
		switch( v.getId()) {
		case R.id.gmale : result = "남자"; break;
		case R.id.gfemale : result = "여자"; break;
		case R.id.gbtn : if(gmale.isChecked()) result = "남자";
		else if (gfemale.isChecked()) result = "여자"; break;
		}
		Toast.makeText(getApplicationContext(), result, Toast.LENGTH_SHORT).show();
	}

	//좋아하는 음식확인 이벤트 처리
	public void checkFood( View v) {
		switch(v.getId()) {
		case R.id.jja: 
			if( jja.isChecked()) myjja = "짜장면"; 
			else myjja = ""; break;
		case R.id.woo: 
			if( woo.isChecked()) mywoo = "우동"; 
			else mywoo = ""; break;
		case R.id.tang: 
			if( tang.isChecked()) mytang = "탕수육"; 
			else mytang = ""; break;
		}
		String result = myjja + " " + mywoo +" " + mytang;
		Toast.makeText(getApplicationContext(), result, Toast.LENGTH_SHORT).show();
		
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.form, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
